package cn.jingyuan.swan.uaa.web.controller;

import cn.jingyuan.swan.cloud.core.Result;
import cn.jingyuan.swan.cloud.core.ResultUtils;
import cn.jingyuan.swan.cloud.oauth2.DefaultOAuth2Helper;
import cn.jingyuan.swan.cloud.oauth2.DefaultUserDetails;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

@Api(tags = "用户服务")
@Slf4j
@RestController
public class UserController {

    /**
     * 获取用户基础信息
     */
    @ApiOperation(value = "获取当前登录用户信息", notes = "获取当前登录用户信息")
    @GetMapping(path = "/user/me", produces = APPLICATION_JSON_VALUE)
    public Result<DefaultUserDetails> me() {
        DefaultUserDetails userDetails = DefaultOAuth2Helper.getUser();
        return ResultUtils.ok(userDetails);
    }

}
